/*-----------------------------------------------------------------------------------
Name: Sangyoon Park
Date: January 23 2023
This do file does : 
	Create variable labels and export codebook
-----------------------------------------------------------------------------------*/
clear all
set matsize 10000
set maxvar 10000
set more off


#delim ;

*** Load dataset;

import excel "${raw_path}/FARMER_COMBINESURVEY_CLEAN.xlsx", firstrow;

*** Label dataset;

lab data "This file contains farmer data collected from baseline and two followup surveys";


*** Label baseline variables;

lab var farmerid "unique id of farmer";
lab var district "[Base] district of farmer";
lab var commune "[Base] commune of farmer";
lab var strata "[Base] strata assigned to farmer";
lab var st_tgroup "[Base] treatment group assigned to farmer";
lab var control_commune "[Base] if group is assigned to control commune";
lab var latitude "[Base] latitude of farm";
lab var longitude "[Base] longitude of farm";
lab var female "[Base_B-1] sex of farmer";
lab var age "[Base_B-2] age of farmer";
lab var education "[Base_B-3] education level achieved";
lab var householdhead"[Base_B-4] head of family";
lab var farmowner"[Base_B-5] owner of dragon fruit farm";
lab var primaryperson"[Base_B-6] primary person of farming";
lab var vietgap"[Base_C-1-a1] have vietgap certificate";
lab var vietgap_year"[Base_C-1-a2] year of vietgap";
lab var globalgap"[Base_C-1-b1] have globalgap certificate";
lab var globalgap_year"[Base_C-1-b2] year of globalgap";
lab var eurogap"[Base_C-1-c1] have eurogap certificate";
lab var eurogap_year"[Base_C-1-c2] year of eurogap";
lab var othercert"[Base_C-1-d1] have other certificate";
lab var othercert_year"[Base_C-1-d2] year of other certificate";
lab var exp_dragon"[Base_C-2] experience dragon fruit farming";
lab var ha_whitedragon"[Base_C-3-a] size of dragon fruit farm (ha)";
lab var tree_whitedragon"[Base_C-3-b] number of dragon fruit trees";
lab var white_age_less1"[Base_C-4-a] trees aged less than 1 year";
lab var white_age_less3"[Base_C-4-b] trees aged less than 3 years";
lab var white_age_less10"[Base_C-4-c] trees aged less than 10 years";
lab var white_age_less20"[Base_C-4-d] trees aged less than 20 years";
lab var white_age_more20"[Base_C-4-e] trees aged more than 20 years";
lab var hours_base"[Base_C-5-a] hours worked";
lab var inc_agr_base"[Base_C-5-b1] percent of income from agriculture";
lab var inc_dragon_base"[Base_C-5-b2] percent of income from dragon fruit farm";
lab var inc_nonagri_base"[Base_C-5-b3] percent of income from non-agriculture";
lab var volume_base"[Base_C-5-c2] volume sold";
lab var price_base"[Base_C-5-c3] average unit price sold";
lab var totrev_base"[Base_C-5-c4] total revenue";
lab var invest_land_base"[Base_C-5-d1] investment in land purchase";
lab var invest_plant_base"[Base_C-5-d2] investment in plant purchase";
lab var invest_post_base"[Base_C-5-d3] investment in post purchase";
lab var cost_equip_base"[Base_C-5-e1] cost on purchase of equipment";
lab var cost_fert_base"[Base_C-5-e2] cost on purchase of fertilizer";
lab var cost_pest_base"[Base_C-5-e3] cost on purchase of pesticide";
lab var cost_facility_base"[Base_C-5-e4] cost on building of facility";
lab var cost_labor_base"[Base_C-5-e5] cost on hired labor";
lab var cost_utility_base"[Base_C-5-e6] cost on payments for utility";
lab var cost_other_base"[Base_C-5-e7] cost on other farm inputs";
lab var record_yield_base"[Base_C-6-a] keep book record of crop yield";
lab var record_chemical_base"[Base_C-6-b] keep book record of chemical use";
lab var pesticide_base"[Base_C-6-c] pesticide use comply with GAP";
lab var irrigation_base"[Base_C-6-d] use drip irrigation system";
lab var storage_base"[Base_C-6-e] keep book record of crop yield";
lab var cementpost_base"[Base_C-6-f] use cement post for tree";
lab var treatment_base"[Base_C-6-g] use pre-harvest treatments";
lab var lighting_base"[Base_C-6-h] use flowering stimulation";
lab var coverfruit_base"[Base_C-6-i] cover fruit with bag or paper";

local group "farmer trader supplier internet tv socialmed other";
local i = 1;
	foreach y of local group {;
		lab var infoprice_`y'"[Base_E-1-a`i'] price info from `y'";
		lab var infodemand_`y'"[Base_E-1-b`i'] market demand info from `y' ";
		lab var infobuyer_`y'"[Base_E-1-c`i'] buyer info from `y' ";
		lab var infostandard_`y'"[Base_E-1-d`i'] quality standards info from `y' ";
		local i = `i'+1;
	};

lab var loan_bank_base"[Base_E-2-a2] ever received loan from bank";
lab var loan_farmer_base"[Base_E-2-b2] ever received loan from other farmers";
lab var loan_trader_base"[Base_E-2-c2] ever received loan from trader";
lab var loan_supplier_base"[Base_E-2-d2] ever received loan from supplier";
lab var loan_friend_base"[Base_E-2-e2] ever received loan from friend orfamily";
lab var loan_other_base"[Base_E-2-f2] ever received loan from other institutions";
lab var save_bank_base"[Base_E-3-a1] usually save at bank";
lab var save_group_base"[Base_E-3-b1] usually save at community saving group";
lab var save_hand_base"[Base_E-3-c1] usually save cash on hand";
lab var save_family_base"[Base_E-3-d1] usually save by giving out loans";
lab var save_other_base"[Base_E-3-e1] usually save in other ways";

lab var contract_q1"[Base_F-1a] never used contract before";
lab var contract_q2"[Base_F-1b] never heard of contract before";
lab var contract_q3"[Base_F-1c] want to have contract";
lab var contract_q4"[Base_F-1d] contract only benefits buyers";
lab var contract_q5"[Base_F-1e] do not trust contract with buyers";
lab var contract_q6"[Base_F-1f] contract restrictive to farmers";
lab var contract_q7"[Base_F-1g] can sell at higher price without contract";
lab var contract_q8"[Base_F-1h] can sell larger quantity without contract";

lab var barrier_q1"[Base_F-2a] major barrier = no access or information";
lab var barrier_q2"[Base_F-2b] major barrier = no technical knowledge";
lab var barrier_q3"[Base_F-2c] major barrier = no money for investment";
lab var barrier_q4"[Base_F-2d] major barrier = not profitable enough";
lab var barrier_q5"[Base_F-2e] major barrier = too risky to invest";


lab var trust_1"[BaseB_A-1-a] trust my family";
lab var trust_2"[BaseB_A-1-b] trust people in my neighborhood";
lab var trust_3"[BaseB_A-1-c] trust people I personally know";
lab var trust_4"[BaseB_A-1-d] trust people met for first time";
lab var trust_5"[BaseB_A-1-e] trust people from other communities";
lab var trust_6"[BaseB_A-1-f] trust people from other countries";

lab var business_1"[BaseB_A-2-a] entrepreneurial survey QA";
lab var business_2"[BaseB_A-2-b] entrepreneurial survey QB";
lab var business_3"[BaseB_A-2-c] entrepreneurial survey QC";
lab var business_4"[BaseB_A-2-d] entrepreneurial survey QD";
lab var business_5"[BaseB_A-2-e] entrepreneurial survey QE";
lab var business_6"[BaseB_A-2-f] entrepreneurial survey QF";
lab var business_7"[BaseB_A-2-g] entrepreneurial survey QG";
lab var business_8"[BaseB_A-2-h] entrepreneurial survey QH";
lab var business_9"[BaseB_A-2-i] entrepreneurial survey QI";
lab var business_10"[BaseB_A-2-j] entrepreneurial survey QJ";
lab var business_11"[BaseB_A-2-k] entrepreneurial survey QK";

lab var confidence_1"[BaseB_A-3-a] self-confidence survey QA";
lab var confidence_2"[BaseB_A-3-b] self-confidence survey QB";
lab var confidence_3"[BaseB_A-3-c] self-confidence survey QC";
lab var confidence_4"[BaseB_A-3-d] self-confidence survey QD";
lab var confidence_5"[BaseB_A-3-e] self-confidence survey QE";
lab var confidence_6"[BaseB_A-3-f] self-confidence survey QF";
lab var confidence_7"[BaseB_A-3-g] self-confidence survey QG";
lab var confidence_8"[BaseB_A-3-h] self-confidence survey QH";
lab var confidence_9"[BaseB_A-3-i] self-confidence survey QI";
lab var confidence_10"[BaseB_A-3-j] self-confidence survey QJ";

lab var present_discount"[BaseB_A-4] present time discounting";
lab var future_discount"[BaseB_B-14] future time discounting";

lab var risky_invest"[BaseB_A-5] risk preference";
lab var raven_total"[BaseB_B] Total score on raven matrices test";


*** Label 1st followup survey variables;

lab var attrit_fu1"[FU1] fail to survey in 1st round followup";
lab var hours_fu1"[FU1_B-1-a] average hours worked per day";
lab var inc_agr_fu1"[FU1_B-1-b1] percent of income from agriculture";
lab var inc_dragon_fu1"[FU1_B-1-b2] percent of income from dragon fruit farm";
lab var inc_nonagri_fu1"[FU1_B-1-b3] percent of income from non-agriculture";
lab var volume_fu1"[FU1_B-1-c2] total volume sold";
lab var avgprice_fu1"[FU1_B-1-c3] average unit price sold";
lab var totrev_fu1"[FU1_B-1-c4] total revenue";
lab var invest_land_fu1"[FU1_B-1-d1] investment in land purchase";
lab var invest_plant_fu1"[FU1_B-1-d2] investment in plant purchase";
lab var invest_post_fu1"[FU1_B-1-d3] investment in post purchase";
lab var cost_equip_fu1"[FU1_B-1-e1] cost on purchase of equipment";
lab var cost_fert_fu1"[FU1_B-1-e2] cost on purchase of fertilizer";
lab var cost_pest_fu1"[FU1_B-1-e3] cost on purchase of pesticide";
lab var cost_facility_fu1"[FU1_B-1-e4] cost on building of facility";
lab var cost_labor_fu1"[FU1_B-1-e5] cost on hired labor";
lab var cost_utility_fu1"[FU1_B-1-e6] cost on payments for utility";
lab var cost_other_fu1"[FU1_B-1-e7] cost on other farm inputs";

lab var loans_since_base_fu1"[FU1_E-1] take out loan since baseline survey";
lab var loans_lendertype_fu1"[FU1_E-2] source of loan";
lab var loans_amount_fu1"[FU1_E-3] amount of loan taken out";

lab var gaptest_score_fu1"[FU1_F] total score on gap knowledge test (max=10)";

lab var blossom_days_fu1"[FU1A_B-1] how many days from blossom of flower";
lab var sweet_sam1_top_fu1"[FU1A_B-2-1a] sweetness of sample 1, top part";
lab var sweet_sam1_mid_fu1"[FU1A_B-2-1b] sweetness of sample 1, mid part";
lab var sweet_sam1_bot_fu1"[FU1A_B-2-1c] sweetness of sample 1, bot part";
lab var sweet_sam2_top_fu1"[FU1A_B-2-2a] sweetness of sample 2, top part";
lab var sweet_sam2_mid_fu1"[FU1A_B-2-2b] sweetness of sample 2, mid part";
lab var sweet_sam2_bot_fu1"[FU1A_B-2-2c] sweetness of sample 2, bot part";
lab var color_sk_sam1_fu1"[FU1A_B-3-a1] skin rating of sample 1";
lab var color_sk_sam2_fu1"[FU1A_B-3-a2] skin rating of sample 2";
lab var color_br_sam1_fu1"[FU1A_B-3-b1] bract rating of sample 1";
lab var color_br_sam2_fu1"[FU1A_B-3-b2] bract rating of sample 2";
lab var weight_sam1_fu1"[FU1A_B-4-1] weight of sample 1";
lab var weight_sam2_fu1"[FU1A_B-4-2] weight of sample 2";
lab var length_sam1_fu1"[FU1A_B-5-1a] length of sample 1";
lab var width_sam1_fu1"[FU1A_B-5-1b] width of sample 1";
lab var length_sam2_fu1"[FU1A_B-5-2a] length of sample 2";
lab var width_sam2_fu1"[FU1A_B-5-2b] width of sample 2";

lab var audit_c1_a_fu1"[FU1A_C-1_a] vietgap audit question 1-a";
lab var audit_c1_b_fu1"[FU1A_C-1_b] vietgap audit question 1-b";
lab var audit_c1_c_fu1"[FU1A_C-1_c] vietgap audit question 1-c";
lab var audit_c2_fu1"[FU1A_C-2] vietgap audit question 2";
lab var audit_c3_fu1"[FU1A_C-3] vietgap audit question 3";
lab var audit_c4_a_fu1"[FU1A_C-4_a] vietgap audit question 4-a";
lab var audit_c4_b_fu1"[FU1A_C-4_b] vietgap audit question 4-b";
lab var audit_c5_a_fu1"[FU1A_C-5_a] vietgap audit question 5-a";
lab var audit_c5_b_fu1"[FU1A_C-5_b] vietgap audit question 5-b";
lab var audit_c5_c_fu1"[FU1A_C-5_c] vietgap audit question 5-c";
lab var audit_c5_d_fu1"[FU1A_C-5_d] vietgap audit question 5-d";
lab var audit_c5_e_fu1"[FU1A_C-5_e] vietgap audit question 5-e";
lab var audit_c6_a_fu1"[FU1A_C-6_a] vietgap audit question 6-a";
lab var audit_c6_b_fu1"[FU1A_C-6_b] vietgap audit question 6-b";
lab var audit_c6_c_fu1"[FU1A_C-6_c] vietgap audit question 6-c";
lab var audit_c6_d_fu1"[FU1A_C-6_d] vietgap audit question 6-d";
lab var audit_c6_e_fu1"[FU1A_C-6_e] vietgap audit question 6-e";
lab var audit_c7_fu1"[FU1A_C-7] vietgap audit question 7";
lab var audit_c8_a_fu1"[FU1A_C-8_a] vietgap audit question 8-a";
lab var audit_c8_b_fu1"[FU1A_C-8_b] vietgap audit question 8-b";
lab var audit_c8_c_fu1"[FU1A_C-8_c] vietgap audit question 8-c";
lab var audit_c9_a_fu1"[FU1A_C-9_a] vietgap audit question 9-a";
lab var audit_c9_b_fu1"[FU1A_C-9_b] vietgap audit question 9-b";
lab var audit_c9_c_fu1"[FU1A_C-9_c] vietgap audit question 9-c";
lab var audit_c9_d_fu1"[FU1A_C-9_d] vietgap audit question 9-d";
lab var audit_c9_e_fu1"[FU1A_C-9_e] vietgap audit question 9-e";
lab var audit_c9_f_fu1"[FU1A_C-9_f] vietgap audit question 9-f";
lab var audit_c9_g_fu1"[FU1A_C-9_g] vietgap audit question 9-g";
lab var audit_c9_h_fu1"[FU1A_C-9_h] vietgap audit question 9-h";
lab var audit_c10_a_fu1"[FU1A_C-10_a] vietgap audit question 10-a";
lab var audit_c10_b_fu1"[FU1A_C-10_b] vietgap audit question 10-b";
lab var audit_c10_c_fu1"[FU1A_C-10_c] vietgap audit question 10-c";
lab var audit_total_fu1"[FU1A_C] total items passed on vietgap audit (max=32)";


*** Label 2nd followup survey variables;

lab var attrit_fu2"[FU2] fail to survey in 2nd round followup";
lab var hours_fu2"[FU2_B-1] average hours worked per day";
lab var volume_fu2"[FU2_B-2-a] total volume sold";
lab var avgprice_fu2"[FU2_B-2-b] average unit price sold";
lab var totrev_fu2"[FU2_B-2-c] total revenue";
lab var invest_land_fu2"[FU2_B-3-a] investment in land purchase";
lab var invest_plant_fu2"[FU2_B-3-b] investment in plant purchase";
lab var invest_post_fu2"[FU2_B-3-c] investment in post purchase";
lab var cost_equip_fu2"[FU2_B-4-a] cost on purchase of equipment";
lab var cost_fert_fu2"[FU2_B-4-b] cost on purchase of fertilizer";
lab var cost_pest_fu2"[FU2_B-4-c] cost on purchase of pesticide";
lab var cost_facility_fu2"[FU2_B-4-d] cost on building of facility";
lab var cost_labor_fu2"[FU2_B-4-e] cost on hired labor";
lab var cost_utility_fu2"[FU2_B-4-f] cost on payments for utility";
lab var cost_other_fu2"[FU2_B-4-g] cost on other farm inputs";

lab var pesttest_before"[FU2_D-2]took pesticide test before ";
lab var pesttest_which"[FU2_D-3] if took test, which testing agency";
lab var pesttest_cheap"[FU2_D-4a] reason for choosing test agency - cheap";
lab var pesttest_reliable"[FU2_D-4b] reason for choosing test agency - reliable";
lab var pesttest_gov"[FU2_D-4c] reason for choosing test agency - government mandate";
lab var pesttest_buyer"[FU2_D-4d] reason for choosing test agency - buyer mandate";
lab var pesttest_friend"[FU2_D-4e] reason for choosing test agency - friend suggestion";
lab var pesttest_other"[FU2_D-4f] reason for choosing test agency - other";

lab var perception_e1"[FU2_E-1] perception of pesticide and food safety Q1";
lab var perception_e2"[FU2_E-2] perception of pesticide and food safety Q2";
lab var perception_e3"[FU2_E-3] perception of pesticide and food safety Q3";
lab var perception_e4"[FU2_E-4] perception of pesticide and food safety Q4";
lab var perception_e5"[FU2_E-5] perception of pesticide and food safety Q5";
lab var perception_e6"[FU2_E-6] perception of pesticide and food safety Q6";
lab var perception_e7"[FU2_E-7] perception of pesticide and food safety Q7";
lab var perception_e8"[FU2_E-8] perception of pesticide and food safety Q8";
lab var perception_e9"[FU2_E-9] perception of pesticide and food safety Q9";
lab var perception_e10"[FU2_E-10] perception of pesticide and food safety Q10";

lab var blossom_days_fu2"[FU2A_B-1] how many days from blossom of flower";
lab var sweet_sam1_top_fu2"[FU2A_B-2-1a] sweetness of sample 1, top part";
lab var sweet_sam1_mid_fu2"[FU2A_B-2-1b] sweetness of sample 1, mid part";
lab var sweet_sam1_bot_fu2"[FU2A_B-2-1c] sweetness of sample 1, bot part";
lab var sweet_sam2_top_fu2"[FU2A_B-2-2a] sweetness of sample 2, top part";
lab var sweet_sam2_mid_fu2"[FU2A_B-2-2b] sweetness of sample 2, mid part";
lab var sweet_sam2_bot_fu2"[FU2A_B-2-2c] sweetness of sample 2, bot part";
lab var color_sk_sam1_fu2"[FU2A_B-3-a1] skin rating of sample 1";
lab var color_sk_sam2_fu2"[FU2A_B-3-a2] skin rating of sample 2";
lab var color_br_sam1_fu2"[FU2A_B-3-b1] bract rating of sample 1";
lab var color_br_sam2_fu2"[FU2A_B-3-b2] bract rating of sample 2";
lab var weight_sam1_fu2"[FU2A_B-4-1] weight of sample 1";
lab var weight_sam2_fu2"[FU2A_B-4-2] weight of sample 2";
lab var length_sam1_fu2"[FU2A_B-5-1a] length of sample 1";
lab var width_sam1_fu2"[FU2A_B-5-1b] width of sample 1";
lab var length_sam2_fu2"[FU2A_B-5-2a] length of sample 2";
lab var width_sam2_fu2"[FU2A_B-5-2b] width of sample 2";

lab var audit_c1_a_fu2"[FU2A_C-1_a] vietgap audit question 1-a";
lab var audit_c1_b_fu2"[FU2A_C-1_b] vietgap audit question 1-b";
lab var audit_c1_c_fu2"[FU2A_C-1_c] vietgap audit question 1-c";
lab var audit_c2_fu2"[FU2A_C-2] vietgap audit question 2";
lab var audit_c3_fu2"[FU2A_C-3] vietgap audit question 3";
lab var audit_c4_a_fu2"[FU2A_C-4_a] vietgap audit question 4-a";
lab var audit_c4_b_fu2"[FU2A_C-4_b] vietgap audit question 4-b";
lab var audit_c5_a_fu2"[FU2A_C-5_a] vietgap audit question 5-a";
lab var audit_c5_b_fu2"[FU2A_C-5_b] vietgap audit question 5-b";
lab var audit_c5_c_fu2"[FU2A_C-5_c] vietgap audit question 5-c";
lab var audit_c5_d_fu2"[FU2A_C-5_d] vietgap audit question 5-d";
lab var audit_c5_e_fu2"[FU2A_C-5_e] vietgap audit question 5-e";
lab var audit_c6_a_fu2"[FU2A_C-6_a] vietgap audit question 6-a";
lab var audit_c6_b_fu2"[FU2A_C-6_b] vietgap audit question 6-b";
lab var audit_c6_c_fu2"[FU2A_C-6_c] vietgap audit question 6-c";
lab var audit_c6_d_fu2"[FU2A_C-6_d] vietgap audit question 6-d";
lab var audit_c6_e_fu2"[FU2A_C-6_e] vietgap audit question 6-e";
lab var audit_c7_fu2"[FU2A_C-7] vietgap audit question 7";
lab var audit_c8_a_fu2"[FU2A_C-8_a] vietgap audit question 8-a";
lab var audit_c8_b_fu2"[FU2A_C-8_b] vietgap audit question 8-b";
lab var audit_c8_c_fu2"[FU2A_C-8_c] vietgap audit question 8-c";
lab var audit_c9_a_fu2"[FU2A_C-9_a] vietgap audit question 9-a";
lab var audit_c9_b_fu2"[FU2A_C-9_b] vietgap audit question 9-b";
lab var audit_c9_c_fu2"[FU2A_C-9_c] vietgap audit question 9-c";
lab var audit_c9_d_fu2"[FU2A_C-9_d] vietgap audit question 9-d";
lab var audit_c9_e_fu2"[FU2A_C-9_e] vietgap audit question 9-e";
lab var audit_c9_f_fu2"[FU2A_C-9_f] vietgap audit question 9-f";
lab var audit_c9_g_fu2"[FU2A_C-9_g] vietgap audit question 9-g";
lab var audit_c9_h_fu2"[FU2A_C-9_h] vietgap audit question 9-h";
lab var audit_c10_a_fu2"[FU2A_C-10_a] vietgap audit question 10-a";
lab var audit_c10_b_fu2"[FU2A_C-10_b] vietgap audit question 10-b";
lab var audit_c10_c_fu2"[FU2A_C-10_c] vietgap audit question 10-c";
lab var audit_total_fu2"[FU2A_C] total items passed on vietgap audit (max=32)";


save "${data_path}/FARMER_COMBINESURVEY_CLEAN", replace;

*** Create codebook for datafile;


log using "${out_path}/codebook_farmer_combinesurvey_clean.log", replace;

codebook,compact;

log close;

clear;











